package com.ljl.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 刘家良
 * @date 2022/10/29 23:13
 * @description /
 */
@Configuration
public class RabbitMqConfig {

    /**
     * 交换机初始化
     * @return /
     */
    @Bean(name = "fanout.exchange")
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanout.exchange", true, false);
    }

    /**
     * 队列初始化
     * @return /
     */
    @Bean(name = "fanout.queue1")
    public Queue fanoutQueue1() {
        return new Queue("fanout.queue1", true, false, false);
    }

    /**
     * 交换队列绑定
     * @param fanoutQueue1 队列/
     * @param fanoutExchange 交换机/
     * @return /
     */
    @Bean
    public Binding bindingSimpleQueue1(@Qualifier("fanout.queue1") Queue fanoutQueue1,
                                       @Qualifier("fanout.exchange") FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

}
